﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Server
{
    public partial class ViewClientDesktop : Form
    {
        public event FormExitEventHandler OnFormExit = null;
        private byte[] data = null;

        public ViewClientDesktop()
        {
            InitializeComponent();
        }

        public void SetImage(byte[] data)
        {
            this.data = data;
        }

        private Image ConvertByteArrayToImage(byte[] data)
        {
            MemoryStream stream = new MemoryStream(data);
            try
            {
                Image img = Image.FromStream(stream);
                return img;
            }
            catch
            {
                return null;
            }
            finally
            {
                stream.Flush();
                stream.Dispose();
            }
        }

        private void ViewClientDesktop_Load(object sender, EventArgs e)
        {
            this.pictureBox1.Image = ConvertByteArrayToImage(data);
        }

        private void ViewClientDesktop_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (this.OnFormExit != null)
            {
                this.OnFormExit(this, new FormExitEvenArgs());
            }
        }
    }
}
